//
// C++ Implementation: function2d
//
// Description: 
//
//
// Author:  <>, (C) 2008
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "function3d.h"

using namespace CoreLib::MathLib ; 
using namespace std  ;

Function3D::Function3D(const std::string & eq )
: IFunction(eq) , mp_ParserVariable ( new Element2D::ValueType (make_pair(0,0)) ), mp_ParserTemporary ( new Element2D(std::make_pair(0,0)) )
{
	mp_Parser->DefineVar("x",&(mp_ParserVariable.get()->first));
	mp_Parser->DefineVar("y",&(mp_ParserVariable.get()->second));

}
Function3D::~Function3D()
{
}
const IElement* Function3D::eval(const IElement & x ) const 
{
	Element2D *pValue = (Element2D*)(&x) ; 
	*mp_ParserVariable = pValue->value() ; 
	mp_ParserTemporary

	/*
    Element1D *pValue = (Element1D*)(&x) ; 
    *mp_ParserVariable = pValue->value() ; 
    mp_ParserTemporary->setValue( mp_Parser->Eval() ) ; 
    return mp_ParserTemporary.get() ; 
	*/
}

const IElement* Function3D::operator ( )(const IElement & x) const 
{
    return eval(x);
}

/*std::vector< double > & Function2D::Rect(const double & xStart, const double & xStop, const double & xStep) const 
{
    static std::vector< double > ret ; 
    ret.clear();
    for ( double i = xStart; i <=xStop; i+=xStep ) 
        ret.push_back(eval(i));
    return ret ; 
}
*/
Element2D::ValueType Function3D::eval(const Element2D::ValueType & x) const
{
    if ( *mp_ParserVariable == x ) 
        return mp_ParserTemporary->value() ; 
    Element2D *pEl = (Element2D*)(eval(Element2D(x)));
    Element2D::ValueType ret = pEl->value() ; 
    return ret ; 
}
Element2D::ValueType Function3D::operator ( )(const Element2D::ValueType & x) const
{
    return eval(x);
}